{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "结果： 4 0 AC自动机\n",
      "原始： AC自动机\n",
      "\n",
      "结果： 8 2 制作成功\n",
      "原始： 制作成功\n",
      "\n",
      "结果： 13 3 下一步\n",
      "原始： 下一步\n",
      "\n",
      "结果： 15 4 我们\n",
      "原始： 我们\n",
      "\n",
      "结果： 23 1 创业商业计划书\n",
      "原始： 创业商业计划书\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import ahocorasick\n",
    "\n",
    "sentence = \"AC自动机制作成功了，下一步我们做创业商业计划书\"\n",
    "\n",
    "AC = ahocorasick.Automaton()\n",
    "dit_list  =[\"AC自动机\",\"创业商业计划书\",\"制作成功\",\"下一步\",\"我们\"]\n",
    "for index,word in enumerate(dit_list):\n",
    "    AC.add_word(word,(index,word))\n",
    "    \n",
    "AC.make_automaton()\n",
    "for end_index, (insert_order, original_value) in AC.iter(sentence):\n",
    "    start_index = end_index - len(original_value) + 1\n",
    "    print(\"\\n结果：\",end_index,insert_order,original_value)\n",
    "    print(\"原始：\",sentence[start_index:start_index + len(original_value)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
